﻿QuotingToolApp.factory('CommonServices', ['$resource','QUOTINGTOOL_CONFIG',
    function ($resource, QUOTINGTOOL_CONFIG) {        

        return {
            //global parameters to share in the route
            newQuoteParamsObj: {},
            selectedAccountParam: null,

            //methods
            getAccounts: function (query) {
                //search SFDC accounts by name or part of the name for autocomplete control
                return $resource(QUOTINGTOOL_CONFIG.baseUrl + '/api/orcl/searchaccount/:name', { name: '@name' }).query({ name: query });
            },
            getCustomers: function (query, masterId) {
                //search oracle customers by customer name or part of the name
                return $resource(QUOTINGTOOL_CONFIG.baseUrl + '/api/orcl/getcustomers/:beginswith/:masteraccountid', { name: '@beginswith', masteraccountid: '@masteraccountid' })
                    .query({ beginswith: query, masteraccountid: masterId });

            },
            getTopDivisions: function () {
                
                return $resource(QUOTINGTOOL_CONFIG.baseUrl + '/api/orcl/gettopdivisions').query();
                //return $resource('http://quotingtool/api/orcl/gettopdivisions').query();
            },            
            getCurrencies: function () {

                return $resource(QUOTINGTOOL_CONFIG.baseUrl + '/api/orcl/getcurrencies/').query();

            },
            getOpportunity: function (opportunityId) {

                return $resource(QUOTINGTOOL_CONFIG.baseUrl + '/api/SF/gettopportunity/:id').get({ id: opportunityId });

            },
            getEmployees: function (query) {
                //search employee detailsby name or part of the name for autocomplete control              

                return $resource(QUOTINGTOOL_CONFIG.baseUrl + '/api/orcl/getpersonname/:beginswith', { beginswith: '@beginswith' }).query({ beginswith: query });
            },
            getTopRegions: function (query) {
                //search employee detailsby name or part of the name for autocomplete control             
                return $resource(QUOTINGTOOL_CONFIG.baseUrl + '/api/orcl/gettopregions/').query();
            }
        };

    }]);
